#include "S5ActionServer.h"
#include <KSockAddress.h>
#include <KSocket.h>
#include "S5ActionClient.h"
#include "S5Server.h"

S5Server *S5ActionServer::server() const
{
    return static_cast<S5Server *>(item());
}

void S5ActionServer::onClientsChanged(LONG current)
{
    server()->onClientsChanged(current);
}

bool S5ActionServer::onNewClient(KSocket *client)
{
    KIpAddress address;
    client->getRemoteAddress(address);
    if (server()->allow(address)) {
        client->setKeepAlive(true, 5000, 1000);
        client->setNoDelay(true);
        server()->ensureAlive(client);
        server()->setAction(client, new S5ActionClient(address, this), true);
        server()->receive(client);
        return true;
    } else {
        return false;
    }
}